package com.fr.report.script.function;

import com.fr.base.FRContext;
import com.fr.base.file.DatasourceManager;
import com.fr.report.TableDataSource;
import com.fr.report.script.Calculator;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;
import java.util.Iterator;

public class TABLEDATAS extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length > 1)
      return Primitive.ERROR_NAME;
    FArray localFArray = new FArray();
    if (paramArrayOfObject.length == 0)
    {
      localFArray = getTableData(0);
      i = 0;
      while (true)
      {
        if (i >= getTableData(1).length())
          break label79;
        localFArray.add(getTableData(1).elementAt(i));
        ++i;
      }
    }
    int i = Integer.parseInt(paramArrayOfObject[0].toString());
    localFArray = getTableData(i);
    label79: return localFArray;
  }

  private FArray getTableData(int paramInt)
  {
    Object localObject2;
    Object localObject3;
    FArray localFArray = new FArray();
    if (paramInt == 0)
    {
      localObject1 = FRContext.getDatasourceManager();
      localObject2 = ((DatasourceManager)localObject1).getTableDataNameIterator();
      while (true)
      {
        if (!(((Iterator)localObject2).hasNext()))
          break label115;
        localObject3 = (String)((Iterator)localObject2).next();
        localFArray.add(localObject3);
      }
    }
    Object localObject1 = getCalculator();
    if (localObject1 != null)
    {
      localObject2 = ((Calculator)localObject1).getCurrentTableDataSource();
      if (localObject2 != null)
      {
        localObject3 = ((TableDataSource)localObject2).getTableDataNameIterator();
        while (((Iterator)localObject3).hasNext())
        {
          String str = (String)((Iterator)localObject3).next();
          localFArray.add(str);
        }
      }
    }
    label115: return ((FArray)(FArray)(FArray)localFArray);
  }

  public Function.Type getType()
  {
    return Function.REPORT;
  }

  public String getCN()
  {
    return "TABLEDATAS():返回报表数据集和服务器数据集名字。\n示例：\n服务器数据集有：ds1,ds2,ds3;报表数据集有dsr1,dsr2.\nTABLEDATAS()等于[dsr1,dsr2,ds1,ds2,ds3].\n而TABLEDATAS(0)返回服务器数据集名字；TABLEDATAS(1)返回报表数据集名字；\nTABLEDATAS(0)等于[ds1,ds2,ds3];TABLEDATAS(1)等于[dsr1,dsr2].";
  }

  public String getEN()
  {
    return "";
  }
}